package com.css.fxfzypg.manage.disasterrisk.verify;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzypg.manage.disasterrisk.repository.entity.DisasterRiskEntity;
import com.css.fxfzypg.util.PlatformObjectUtils;
import org.springframework.stereotype.Component;


@Component
public class ExcelVerifyHandler implements IExcelVerifyHandler<DisasterRiskEntity> {

    @Override
    public ExcelVerifyHandlerResult verifyHandler(DisasterRiskEntity disasterRiskEntity) {

        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuilder message = new StringBuilder("");

        if(PlatformObjectUtils.isEmpty(disasterRiskEntity.getDisasterName()) && PlatformObjectUtils.isEmpty(disasterRiskEntity.getProvince()) && PlatformObjectUtils.isEmpty(disasterRiskEntity.getCity()) && PlatformObjectUtils.isEmpty(disasterRiskEntity.getCounty()) && PlatformObjectUtils.isEmpty(disasterRiskEntity.getDisasterName())  ){
            result.setMsg(message.toString());
            return result;
        }

        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getDisasterName())) {
            result.setSuccess(false);
            message.append("灾害风险点名称 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getProvince())) {
            result.setSuccess(false);
            message.append("灾害风险点位置-省 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getCity())) {
            result.setSuccess(false);
            message.append("灾害风险点位置-市 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getCounty())) {
            result.setSuccess(false);
            message.append("灾害风险点位置-区/县 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getDisasterName())) {
            result.setSuccess(false);
            message.append("灾害风险点位置-详细地址 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getLongitude())) {
            result.setSuccess(false);
            message.append("经度 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getLatitude())) {
            result.setSuccess(false);
            message.append("纬度 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getCounty())) {
            result.setSuccess(false);
            message.append("灾害风险类型 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(disasterRiskEntity.getDisasterDescribe())) {
            result.setSuccess(false);
            message.append("灾害风险点描述 不能为空！");
        }
        if (PlatformObjectUtils.isNotEmpty(disasterRiskEntity.getDisasterDescribe())) {
            if (disasterRiskEntity.getDisasterDescribe().length()>600){
                result.setSuccess(false);
                message.append("灾害风险点描述大于字数限制请缩短描述字数至300个汉字内、");
            }
        }

        result.setMsg(message.toString());
        return result;
    }
}
